package com.lovo.controller;

import com.lovo.result.GlobalHandleException;
import com.lovo.result.ResponseResult;
import com.lovo.result.ResultCode;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@ResponseResult
public class IndexController {
    @GetMapping("/getSession")
    public Object getSession(HttpServletRequest request) throws GlobalHandleException {
        Object user = request.getSession().getAttribute("user");
        if (user == null) {
            throw new GlobalHandleException(ResultCode.USER_NOT_LOGGED_IN);
        }
        return user;
    }

    @GetMapping("/removeSession")
    public Object removeSession(HttpServletRequest request) {
        request.getSession().removeAttribute("user");
        return null;
    }

}
